<template>
	<view class="pd mt100">
		<view class="z9 fz26">
			该组织管理员权限授权
		</view>
		<view class="dsfsdttywer">
			<view class="mt20 pr parent">
				<view class="kjhnderty yj4 pr" :class="sd.cls" v-for="sd in sqssf" >
					<icon type="success" size="18" color="#fff" class="dsfrtyswr" />
					<view class="jjhdertt cen">
						<image :src="'../../static/img/AddViceKey/'+sd.icon" class="jhhdrettw cz" :class="sd.classname" mode="widthFix"></image>
					</view>
					<view class="cf fz26 cen">{{sd.name}}</view>
				</view>
			</view>
		</view>
		<!-- <navigator class="wanhgbsert cf" url="SharingAuthorization">
			完成
		</navigator> -->
	</view>
</template>
<script>
	export default {
		data() {
			return {
				sqssf: [{
						icon: 'kjjhfc.png',
						classname: '',
						name: '开关锁',
						cls: '',
						id:1
					},
					{
						icon: 'kjjhfd.png',
						classname: 'ab',
						name: '启动熄火',
						cls: '',
						id:2
					},
					{
						icon: 'kjjhfe.png',
						classname: 'ac',
						name: '分发副钥匙',
						cls: '',
						id:3
					},
					{
						icon: 'kjjhff.png',
						classname: 'ad',
						name: '远程控制',
						cls: '',
						id:4
					},
					{
						icon: 'kjjhfg.png',
						classname: 'ae',
						name: '实时位置',
						cls: '',
						id:5
					},
					{
						icon: 'kjjhfh.png',
						classname: 'af',
						name: '临时授权',
						cls: '',
						id:6
					}
				],
				carid:"",
				gid:""
			}
		},
		components: {},
		onLoad(options) {
			console.log(options.carid,options.gid)
			this.authority(options.carid,options.gid)
			this.carid=options.carid
			this.gid=options.gid
		},
		methods: {
			kjssf(sd) {
				if (sd.cls) {
					sd.cls = ""
				} else {
					sd.cls = "act"
				}
			},
			async authority(id,gid){				
				let aty=await this.get('/api/car/'+id+'/group_authority/'+gid)
				console.log("展示",aty.data.authority)
				this.sqssf.filter(function(x){					
					aty.data.authority.map(function(a){
						if(a==x.id){
							x.cls='act'
						}
					})
				})				
			},
			async cancel(id,gid){				
				let params={}
				params.ids=gid
				params.cid=id
				let remove=await this.get('/api/car/cancel_authorization',params,'DELETE')
				console.log("删除权限",remove)
				if(remove.code==0){
					uni.showToast({
						icon:"none",
						title:'删除成功'
					})
				}
			}
		},
		onNavigationBarButtonTap() {
			var that=this
			uni.showActionSheet({
				itemList: ['取消授权'],
				itemColor: '#FC5A5A',
				success(e) {
					if (e.tapIndex == 0) {
						uni.showModal({
							title: '',
							content: '您确定要取消该车辆在本群中的授权吗？',
							success: function (res) {
								if (res.confirm) {
									console.log('用户点击确定');
									that.cancel(that.carid,that.gid)
									setTimeout(function(){
										uni.navigateBack({
											
										})
									},2000)
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					}
				}
			})
		},
		mounted() {}
	}
</script>
<style scoped>
	.dsfsdttywer {
		min-height: 700upx;
	}

	.wanhgbsert {
		height: 100upx;
		background: linear-gradient(180deg, rgba(27, 213, 185, 1) 0%, rgba(22, 137, 213, 1) 100%);
		border-radius: 12upx;
		text-align: center;
		line-height: 100upx;
	}
</style>
